﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using YJKArchUtils.Utils;

namespace YJKColumnModify.WallAlignToColumn
{
	public class WallFilter : ISelectionFilter
	{
		public WallFilter(Autodesk.Revit.DB.Document doc, Line line)
		{
			this.m_doc = doc;
			this.m_line = line;
		}

		public bool AllowElement(Element elem)
		{
			if (elem is Wall)
			{
				Curve curve = ((elem as Wall).Location as LocationCurve).Curve;
				return !(curve is Arc) && !Geometry.IsVertical(this.m_line.Direction, (curve as Line).Direction, 1E-09);
			}
			return false;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			PlanarFace planarFace = this.m_doc.GetElement(reference).GetGeometryObjectFromReference(reference) as PlanarFace;
			return !planarFace.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ) && !planarFace.FaceNormal.IsAlmostEqualTo(-XYZ.BasisZ);
		}

		private Document m_doc;

		private Line m_line;
	}
}
